package com.logistics.version.entity.model;

import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import com.logistics.version.entity.domain.Version;
import lombok.Data;

@Data
public class VersionRow {

    private Integer id;

    private String appName;

    private String versionName;

    private String VersionCode;

    private String fileName;

    private String targetFileName;

    private String versionPath;

    private String versionContext;

    private String creator;

    private String createTime;

    private String updater;

    private String updateTime;

    public VersionRow(){}

    public VersionRow(Version version){
        this.id = version.getId();
        this.appName = version.getAppName();
        this.versionName = version.getVersionName();
        this.fileName = version.getFileName();
        this.VersionCode = StringUtils.isNotNull(version.getVersionCode()) ? version.getVersionCode().toString() : null;
        this.targetFileName = version.getTargetFileName();
        this.versionPath = version.getVersionPath();
        this.versionContext = version.getVersionContext();
        this.creator = version.getCreator();
        this.createTime = DateUtils.dateToStringFormat(version.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
        this.updater = version.getUpdater();
        this.updateTime = DateUtils.dateToStringFormat(version.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
    }

    public static VersionRow build(Version version){
        if(StringUtils.isNull(version)){
            return null;
        }
        return new VersionRow(version);
    }
}
